import { RouteConfig } from "vue-router";
import { IViewItem } from "@/types/IViewItem";

export class RoutesTool {
  public static Layout(children: RouteConfig[], path = ""): RouteConfig {
    return {
      children,
      component: () => import(`@/layout/Index.vue`),
      path
    };
  }

  public static Routes(viewItems: IViewItem[]): RouteConfig[] {
    const routes: RouteConfig[] = [];
    viewItems.map(viewItem => {
      console.log(viewItem);
      if (typeof viewItem.RoutePath != "undefined") {
        routes.push(this.Route(viewItem));
      }
      if (viewItem.Items) {
        routes.push(...this.Routes(viewItem.Items));
      }
    });

    console.log(routes);
    return routes;
  }

  public static Route(viewItem: IViewItem): RouteConfig {
    return {
      name: viewItem.Name,
      component: () => import(`@/views/${viewItem.FilePath}`),
      path: viewItem.RoutePath!
    };
  }
}
